<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/jquery-2.0.2.min.js"></script>
    <script src="/crypto-js.js"></script>
</head>

<body>
    111

    <script>
        $(document).ready(function () {
            // let secret = 'Y%BG9GjXU:p^FaW~';
            // $.post('/generate', { r: Math.random() }, function (data) {
            //     console.log(data);
            //     setInterval(function () {
            //         $.post('/api_one', { token: data.token }, function (result) {
            //             console.log('a', result);
            //         }, 'json');
            //     }, 3000);

            //     setInterval(function () {
            //         $.ajax({
            //             url: "/api_two", type: 'POST', dataType: 'json', headers: { Authorization: 'Bearer ' + CryptoJS.AES.encrypt(data.token, secret).toString() }, success: function (result) {
            //                 console.log('b', result);
            //             }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            //                 console.log('b', errorThrown);
            //             }
            //         });

            //     }, 3000);

            // }, 'json');
        });
    </script>

    <script>
        function getRandomInt(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
        async function post(url, data) {
            let secret = 'Y%BG9GjXU:p^FaW~';
            let additional_params = {
                _RAND_: getRandomInt(100000, 999999),
                _TIME_: parseInt(new Date().getTime() / 1000),
                _SIGN_: '',
            };
            additional_params._SIGN_ = CryptoJS.MD5('' + additional_params._RAND_ + additional_params._TIME_ + secret).toString().toUpperCase();
            data._VERIFY_ = JSON.stringify(additional_params);
            data._VERIFY_ = CryptoJS.AES.encrypt(data._VERIFY_, secret).toString();
            return new Promise((resolve, reject) => {
                $.post(url, data, function (data) {
                    resolve(data);
                }, 'json');
            });

        }

        async function start() {
            let result = await post('/api_three', { title: 'hello' });
            console.log(result);
        }
        start();
    </script>
</body>

</html>